import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-11-02
 * Time: 16:42
 */
public class TestH14 {
    public static void main(String[] args) {
        int[] ratings = {1,0,2};
        int ret = candy(ratings);
        System.out.println(ret);
    }
    public static int candy(int[] ratings) {
        int n = ratings.length;
        int[] left = new int[n];
        int[] right = new int[n];
        Arrays.fill(left,1);
        Arrays.fill(right,1);

        for(int i = 1; i < n; i++) {
            if(ratings[i-1] < ratings[i]) {
                left[i] = left[i-1]+1;
            }
        }
        for(int i = n-2; i >= 0; i--) {
            if(ratings[i+1] < ratings[i]) {
                right[i] = right[i+1]+1;
            }
        }
        int ret = 0;         
        for(int i = 0; i < n; i++) {
            ret += Math.max(left[i],right[i]);
        }
        return ret;
    }


}
